package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.KnowledgeContent;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface KnowledgeContentMapper {

    // 根据知识点 ID 查询内容（用于前端点击知识点加载内容）
    @Select("SELECT * FROM knowledge_contents WHERE point_id = #{pointId} ORDER BY order_no ASC")
    List<KnowledgeContent> getContentsByPointId(@Param("pointId") Integer pointId);

    // 插入新的内容记录
    @Insert("INSERT INTO knowledge_contents (point_id, course_id, title, content, order_no, media_url, status) " +
            "VALUES (#{pointId}, #{courseId}, #{title}, #{content}, #{orderNo}, #{mediaUrl}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "contentId")
    int insertContent(KnowledgeContent content);

    // 更新内容
    @Update("UPDATE knowledge_contents SET title=#{title}, content=#{content}, media_url=#{mediaUrl}, " +
            "status=#{status}, order_no=#{orderNo}, update_time=NOW() WHERE content_id=#{contentId}")
    int updateContent(KnowledgeContent content);

    // 删除内容
    @Delete("DELETE FROM knowledge_contents WHERE content_id = #{contentId}")
    int deleteContent(@Param("contentId") Integer contentId);
}